#!/bin/bash

source "$METIS_HOME"metis.config

# Simple script to identify live hosts. Takes into account 3 indicators; open ports, ping and dns. Output is a file called hosts.alive.unique in the pentest working directory

# Live host indicators
cat "$workingDir"targets.ping.result.nmap | grep "Nmap scan report" | awk '{print $5}' >> "$workingDir"hosts.alive
cat "$workingDir"targets.dns.result.nmap | grep "Nmap scan report" | grep -r "(.*)" -o | sed 's/[()]//g' >> "$workingDir"hosts.alive
sqlite3 "$database" 'select distinct ipaddress from services where state = "open"' >> "$workingDir"hosts.alive

# output only live hosts
sort -u "$workingDir"hosts.alive > "$workingDir"hosts.alive.unique

echo "---------------------------------------------------------------------"
echo "+" `wc -l "$workingDir"hosts.alive.unique | awk {'print $1'}` "live hosts identified"
echo "+ Unique list of live hosts has been output to ${workingDir}hosts.alive.unique"
